Ext.require(  
        [  
            'Ext/ux/XHtmlEditor'  
         ]          
);

printGrowthRecord = function(){
	
	    Ext.define('summaryModel',{
	        extend: 'Ext.data.Model',
	        fields: [
	            {name: 'summaryId',type: 'String'},
	             {name: 'studentId',type: 'String'},
	             {name: 'title',type: 'String'},
	             {name: 'contentText', type: 'String'},
	             {name: 'createDate', type: 'String'},
	             {name: 'state',type: 'String'},
	             {name:'remark',type:'String'},
	             {name:'visible',type:'String'},
	             {name:'academicYear',type:'String'},
	             {name:'modifyDateLimit',type:'String'}
	         ]
	    });
		
	    var isVisibleStore = getStaticDataStore('isVisible');
	    var grade = getStaticDataStore('grade');
	    
		var summaryStore = Ext.create('Ext.data.Store',{
			pageSize:10,
			model: summaryModel,
		    autoLoad:true,
		    proxy:{
		        type: 'ajax',
		        url: 'searchSummaryListAction.action',
		        reader:{
		           type: 'json',
		           root: 'resultList.list',            
		           totalProperty: 'resultList.total'
		        },
		        extraParam:{
		            	
		        }
		   }
		       
		   });
		var label1 = new Ext.form.Label({
          //  id:"labelID",
            text:"    ",
            //height:100,//默认auto
            width:30,//默认auto
        });
		var label2 = new Ext.form.Label({
	          //  id:"labelID",
	            text:"    ",
	            //height:100,//默认auto
	            width:30,//默认auto
	        });
		var printInfo = Ext.create('Ext.Button', {
		    text: '打印个人信息',
		    renderTo: Ext.getBody(),
		    handler: function() {
		    	prn0_preview();
		    }
		});
		var printSummary = Ext.create('Ext.Button', {
		    text: '打印自我总结',
		    renderTo: Ext.getBody(),
		    handler: function() {
		    	var selectedKeys = grid.getSelectionModel().getSelection();
				if(selectedKeys.length == 0){
					Ext.Msg.alert("提示", "请在总结列表中一条记录！");
					return;
				}
				prn1_preview(selectedKeys);	
		    }
		});
		var printPlan = Ext.create('Ext.Button', {
		    text: '打印人生规划书',
		    renderTo: Ext.getBody(),
		    handler: function() {
		    	prn2_preview();
		    }
		});
		var checkBox = Ext.create('Ext.selection.CheckboxModel');
		 
	 
	   // var sm=new Ext.grid.CheckboxSelectionModel();
		var grid = Ext.create('Ext.grid.GridPanel',{
			store:summaryStore,
			columnLines:true,
			selModel:checkBox,
			disableSelection:false,
			loadMask:true,
		
			columns:[
			         {xtype: 'rownumberer',text:'序号',width:40},
			         {text:'编号',width:'10%',dataIndex:'summaryId',sortable:true},
			         {text:'标题',width:'20%',dataIndex:'title',sortable:true},
			         {text:'内容',width:'45%',dataIndex:'contentText',hidden:true},
			         {text:"创建时间",width:'15%',dataIndex:'createDate',renderer : function(_registerDate){
			             return _registerDate.replace("T"," ").substring(0,16);
			         }},
			         {text:'备注',width:'10%',dataIndex:'remark'},
			      
			         ],
			
			width:'100%',
			title:"自我总结列表",
			loadMask:true,
			pageSize: 5,
			dockedItems:[{
				dock:'top',
				xtype:'toolbar',//"<span style='color:red'>双击可以修改</span>",'-',	
				items:[{
					width:300,
					fieldLabel:'搜索',
					labelWidth:70,
					xtype:'searchfield',
					store:summaryStore			
				},{
					xtype:'label',
					html:'<div style="font-size:12px;color:red">标题模糊查询</div>'
				}]		
			},{
				dock:'bottom',
				xtype:'pagingtoolbar',	
				store:summaryStore,
				displayInfo:true,
				displayMsg:'显示{0}-{1}条，共计{2}条',
				emptyMsg:"没有数据"
			},{
				dock:'bottom',
				xtype:'label',
				html:'<div style="font-size:12px;color:red">*选择需要打印的行</div>'
			}],
			listeners:{  
				//双击事件
				itemdblclick : function( grid, record, item, index, e, eOpts){  
					/*var selectedKeys = grid.getSelectionModel().getSelection();
					//showDetails(selectedKeys);
					Preview(selectedKeys);*/
					
				       }  
			}
		});
	
	var panel = Ext.create('Ext.panel.Panel',{
		//enableTabScroll: true,
		width:'100%',
		//height:400,
		autoScroll : true,
		//x:100,
		//layout: 'column',
       // layout: 'border',
		//margin:'2 10 3 10',
		//title:"kkkkkk",
		/*region:'center',
		layout: {
		    type: 'hbox',
		    align: 'middle ',
		    pack: 'center'
		},*/
		/*layout:{    
			align: 'center',
            type:'table',//表格布局    
            columns:2 //设置表格布局默认列数为2列    
        },*/ 
       items: [
{
	//layout: 'column',
	region:'center',
	layout: {
	    type: 'hbox',
	    align: 'middle ',
	    pack: 'center'
	},
	//height:100,
    xtype:'panel',
    border:false,
    items:[ printInfo,label1,printPlan ,label2,printSummary
		]
},grid],
        listeners: {
            'afterrender': function () {
         	  // Ext.Msg.alert("ss",store.first().get('studentId'));           	
            }
        }
	});
	
	var LODOP; //声明为全局变量    
	
	//打印个人信息
	function prn0_preview(){
		 Ext.Ajax.request( {
		    	url : "qryStudentInfoByIdAction.action", 
		    	params : {
		    		
		    	}, //参数
		    	success : function(response, option) {
		    		
		    		var obj = Ext.decode(response.responseText);
		    
		    		var studentName = obj.list[0].studentName;
		    		var studentId = obj.list[0].studentId;
		    		var studentSex = obj.list[0].sex;
		    		var studentPhoto = obj.list[0].photo;
		    		//Ext.getCmp('studentImage').getEl().dom.src= obj.list[0].photo;
		    		//Ext.Msg.alert("失败", Ext.getCmp('studentImage').getEl().dom.src);
		    		
		    		var studentEmail = obj.list[0].email == null?"":obj.list[0].email;
		    		//Ext.getCmp('studentImage').setValue();
		    		// Ext.getCmp('studentImage').getEl().dom.src = obj.list[0].phone;
		    		var studentAcademy = obj.list[0].academy == null?"":obj.list[0].academy;
		    		var studentProfessionnal = obj.list[0].professional == null?"":obj.list[0].professional;
		    		var studentGrade = obj.list[0].grade == null?"":obj.list[0].grade;
		    		var index = grade.find('valueId',studentGrade); 
	       			 if(index != -1){
	       				 var r = grade.getAt(index);
	       				studentGrade =  r.get("valueName");
	       			 }
		    		
		    		var studentClass = obj.list[0].inclass == null?"":obj.list[0].inclass;
		    		var studentTeach = obj.list[0].counselor == null?"":obj.list[0].counselor;
		    		//Ext.Msg.alert("失败", obj.list[0].birth);
		    		var studentBirth = obj.list[0].birth == null?"":obj.list[0].birth.substring(0,10);
		    		var studentPhone = obj.list[0].phone == null?"":obj.list[0].phone;
		    		var studentPoliticalStatus = obj.list[0].politicalStatus == null?"":obj.list[0].politicalStatus;
		    		var studentNational = obj.list[0].national == null?"":obj.list[0].national;
		    		var studentNativePlace = obj.list[0].nativePlace == null?"":obj.list[0].nativePlace;
		    		var studentCardId = obj.list[0].cardId == null?"":obj.list[0].cardId;
		    		var studentDorm = obj.list[0].dorm == null?"":obj.list[0].dorm;
		    		var studentHobby = obj.list[0].hobby == null?"":obj.list[0].hobby;
		    		var studentSpecialty = obj.list[0].specialty == null?"":obj.list[0].specialty;
		    		var studentRemark = obj.list[0].remark == null?"":obj.list[0].remark;
		    		var str = "<center>";
		    		str += '<h2>基本信息</h2>';
		    		str += '<table border="1" cellspacing="0" cellpadding="0" >';
		    		str += '<tr height="30"><td width="60">姓名：</td> <td width="160">'+studentName+'</td><td width="60">学号：</td><td width="160">'+studentId+'</td><td colspan="2" rowspan="3" align="center" width="220"><img src="'+studentPhoto+'" width="75" height="90"/></td></tr>';
		    		str += '<tr height="30"><td width="60">性别：</td> <td width="160">'+studentSex+'</td><td width="60">民族：</td><td width="160">'+studentNational+'</td></tr>';
		    		str += '<tr height="30"><td width="60">籍贯：</td> <td width="160">'+studentNativePlace+'</td><td width="60">政治<br>面貌：</td><td width="160">'+studentPoliticalStatus+'</td></tr>';
		    		str += '<tr height="30"><td width="60">邮箱：</td> <td width="160">'+studentEmail+'</td><td width="60">电话：</td><td width="160">'+studentPhone+'</td><td td width="60">身份<br>证号：</td><td width="160">'+studentCardId+'</td></tr>';
		    		str += '<tr height="30"><td width="60">学院：</td><td width="160">'+studentAcademy+'</td><td width="60">专业：</td> <td width="160">'+studentProfessionnal+'</td><td width="60">年级：</td><td width="160">'+studentGrade+'</td></tr>';
		    		str += '<tr height="30"><<td width="60">班级：</td><td width="160">'+studentClass+'</td><td width="60">辅导员：</td><td width="160">'+studentTeach+'</td><td width="60">出生<br>日期：</td> <td width="160">'+studentBirth+'</td></tr>';
		    		str += '<tr min-height="30"><td>爱好：</td> <td colspan="5">'+studentHobby+'</td></tr>';
		    		str += '<tr min-height="30"><td>特长：</td> <td colspan="5">'+studentSpecialty+'</td></tr>';
		    		str += '<tr min-height="30"><td>简介：</td> <td colspan="5">'+studentRemark+'</td></tr>';
		    		str += '</table>';
		    		str += '</center>';
		    		LODOP=getLodop();  
	    			LODOP.SET_PRINT_STYLEA(0,"Horient",2);
	    			LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_分页输出一");
	    			LODOP.ADD_PRINT_HTM(50,75,650,950,str);
	    			LODOP.PREVIEW();
		    		
		    	},
		    	failure : function(response, option) {
		    		Ext.Msg.alert("失败", "系统错误");
		    	}
		    	});
	}
	//打印总结
	function prn1_preview(selectedKeys) {	
		var i;
		LODOP=getLodop();  
		LODOP.SET_PRINT_STYLEA(0,"Horient",2);
		LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_分页输出一");
		for(i = 0;i<selectedKeys.length;i++){
			var time = selectedKeys[i].get("createDate");
			time = time.substring(0,10);
			var strTitle = '<center><h2>'+selectedKeys[i].get("title")+'</h2><span style="font-size:12px;">创建时间：'+time+'</span></center>';
			var remark = selectedKeys[i].get("remark");
			if(remark == null || remark == 'null')remark ="无";
			var strRemark = "<br><br><br>备注："+remark;
			var com = document.createElement("div"); 
			com.innerHTML = strTitle+selectedKeys[i].get("contentText")+strRemark;
			//document.getElementById("XXXX").appendChild(com);
			LODOP.ADD_PRINT_HTM(50,100,610,950,com.innerHTML);
			LODOP.NewPage();
		}
		LODOP.PREVIEW();	
	};
	//打印人生规划书
	function prn2_preview() {
		Ext.Ajax.request( {
	    	url : "qryLifePlanByParameterAction.action", 
	    	async:false,//同步加载
	    	params : {
	    		
	    	}, //参数
	    	success : function(response, option) {
	    		var obj = Ext.decode(response.responseText);
	    		if(obj.list.length > 0){
	    			data = obj.list[0];
	    			var contentText=data.conentText;
	    			var createDate = data.createDate;
	    		    createDate = createDate.substring(0,10);
	    		    var remark=data.remark;if(remark == null || remark == 'null')remark='无';
	    		    var evaluate=data.evaluate;if(evaluate == null || evaluate == 'null')evaluate='';
	    		    var strTitle = '<center><h2>人生规划书</h2><span style="font-size:12px;">创建时间：'+createDate+'</span></center>';
	    		    var strRemark = "<br><br><br>备注："+remark;
	    		    var strEvaluate = "<br>导师评语："+evaluate;
	    		    LODOP=getLodop();  
	    			LODOP.SET_PRINT_STYLEA(0,"Horient",2);
	    			LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_分页输出一");
	    			LODOP.ADD_PRINT_HTM(50,100,610,950,strTitle+contentText+strRemark+strEvaluate);
	    			LODOP.PREVIEW();
	    		}else{
	    			Ext.Msg.alert("失败", "你还没有创建人生规划书，不能打印！");
	    		}
	    	},
	    	failure : function(response, option) {
	    		Ext.Msg.alert("失败", "人生规划书获取失败!");
	    	}
	    	});
			
	};
	return panel;
}